using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop;
using System;
using System.Collections;
using System.Data;
using System.Web.Profile;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class UserControls_PayMent : Howave_ControlCache
{
	protected RadioButtonList paytype;
	protected HtmlTable Table1;
	protected Label Label1;
	protected HiddenField hfdeliverPayType;
	protected HtmlGenericControl deliverInfo;
	protected UpdatePanel upDeliver;
	protected RadioButtonList rblDeliverFashion;
	protected RadioButtonList deliverType;
	protected UpdatePanel UpdatePanel2;
	protected HtmlGenericControl confirDeliver;
	protected LinkButton LinkAddress;
	protected UpdatePanel UpdatePanel5;
	protected HtmlTableRow add_new_address;
	protected RadioButtonList address_list;
	protected UpdatePanel UpdatePanel3;
	protected HtmlTableRow my_receive_address_list;
	protected TextBox ContacterName;
	protected RequiredFieldValidator RequiredFieldValidator2;
	protected RegularExpressionValidator RegularExpressionValidator4;
	protected Label LbErrorName;
	protected TextBox TelBox;
	protected RegularExpressionValidator RegularExpressionValidator1;
	protected TextBox HomePhoneBox;
	protected RegularExpressionValidator RegularHomeTel;
	protected DropDownList Province;
	protected DropDownList City;
	protected DropDownList ddlArea;
	protected Label LbError;
	protected UpdatePanel UpdatePanel1;
	protected TextBox Address;
	protected RequiredFieldValidator RequiredFieldValidator1;
	protected TextBox EmailBox;
	protected RequiredFieldValidator RequiredFieldValidator4;
	protected RegularExpressionValidator RegularExpressionValidator2;
	protected TextBox zipCode;
	protected RequiredFieldValidator RequiredFieldValidator3;
	protected RegularExpressionValidator RegularExpressionValidator3;
	protected CheckBox CheckBox1;
	protected Button CmdNewAddress;
	protected HtmlTable show_new_address;
	protected Panel pnlAddress;
	protected UpdatePanel UpdatePanel4;
	protected HtmlTable manage_address_tr;
	protected Literal TeamNumLiteral;
	private Shop_Address _addr;
	private Conn conn = new Conn();
	private Shop_DeliverType _shop_deliver = null;
	protected string _shopID = string.Empty;
	protected string _UserID = string.Empty;
	protected string _ContacterName = string.Empty;
	protected string _Address = string.Empty;
	protected string _ZipCode = string.Empty;
	protected string _Mobile = string.Empty;
	protected string _Phone = string.Empty;
	protected string _Email = string.Empty;
	protected string _PayType = string.Empty;
	protected string _DeliverType = string.Empty;
	private Shop_PayType _shop_PayType = null;
	private Shop_DeliverType _Shop_DeliverType = null;
	private Shop_Address _shop_address = null;
	private string _ProductIDS;
	private Shop_Product _shop_product = null;
	private Shop_City _city;
	private string m_selectedProv;
	private string m_selectedCity;
	private Shop_Shop _shop_shop = null;
	private Shop _shop = null;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected Shop_Address m_addr
	{
		get
		{
			Shop_Address addr;
			if (this._addr == null)
			{
				this._addr = new Shop_Address(this.conn);
				addr = this._addr;
			}
			else
			{
				addr = this._addr;
			}
			return addr;
		}
	}
	public Shop_DeliverType shop_deliver
	{
		get
		{
			if (this._shop_deliver == null)
			{
				this._shop_deliver = new Shop_DeliverType(this.conn);
			}
			return this._shop_deliver;
		}
	}
	public string shopID
	{
		get
		{
			return this._shopID;
		}
		set
		{
			this._shopID = value;
		}
	}
	public string UserID
	{
		get
		{
			return this._UserID;
		}
		set
		{
			this._UserID = value;
		}
	}
	public string shop_ContacterName
	{
		get
		{
			this._ContacterName = this.ContacterName.Text;
			return this._ContacterName;
		}
		set
		{
			this._ContacterName = value;
		}
	}
	public string shop_Address
	{
		get
		{
			return this._Address;
		}
	}
	public string ZipCode
	{
		get
		{
			return this._ZipCode;
		}
	}
	public string Mobile
	{
		get
		{
			return this._Mobile;
		}
	}
	public string Phone
	{
		get
		{
			return this._Phone;
		}
	}
	public string shop_Email
	{
		get
		{
			return this._Email;
		}
	}
	public string PayType
	{
		get
		{
			return this._PayType;
		}
	}
	public string DeliverType
	{
		get
		{
			return this._DeliverType;
		}
		set
		{
			this._DeliverType = value;
		}
	}
	protected Shop_PayType shop_PayType
	{
		get
		{
			Shop_PayType shop_PayType;
			if (this._shop_PayType == null)
			{
				this._shop_PayType = new Shop_PayType();
				shop_PayType = this._shop_PayType;
			}
			else
			{
				shop_PayType = this._shop_PayType;
			}
			return shop_PayType;
		}
	}
	protected Shop_DeliverType shop_deliverType
	{
		get
		{
			Shop_DeliverType shop_DeliverType;
			if (this._Shop_DeliverType == null)
			{
				this._Shop_DeliverType = new Shop_DeliverType();
				shop_DeliverType = this._Shop_DeliverType;
			}
			else
			{
				shop_DeliverType = this._Shop_DeliverType;
			}
			return shop_DeliverType;
		}
	}
	protected Shop_Address shop_address
	{
		get
		{
			Shop_Address shop_address;
			if (this._shop_address == null)
			{
				this._shop_address = new Shop_Address();
				shop_address = this._shop_address;
			}
			else
			{
				shop_address = this._shop_address;
			}
			return shop_address;
		}
	}
	public string ProductIDS
	{
		get
		{
			return this._ProductIDS;
		}
		set
		{
			this._ProductIDS = value;
		}
	}
	protected Shop_Product shop_product
	{
		get
		{
			Shop_Product shop_product;
			if (this._shop_product == null)
			{
				this._shop_product = new Shop_Product();
				shop_product = this._shop_product;
			}
			else
			{
				shop_product = this._shop_product;
			}
			return shop_product;
		}
	}
	protected Shop_City m_city
	{
		get
		{
			Shop_City city;
			if (this._city == null)
			{
				this._city = new Shop_City();
				city = this._city;
			}
			else
			{
				city = this._city;
			}
			return city;
		}
	}
	public string SelectedProvince
	{
		get
		{
			return this.Province.SelectedValue;
		}
		set
		{
			this.m_selectedProv = value;
		}
	}
	public string SelectedCity
	{
		get
		{
			return this.City.SelectedValue;
		}
		set
		{
			this.m_selectedCity = value;
		}
	}
	protected Shop_Shop shop_shop
	{
		get
		{
			Shop_Shop shop_shop;
			if (this._shop_shop == null)
			{
				this._shop_shop = new Shop_Shop();
				shop_shop = this._shop_shop;
			}
			else
			{
				shop_shop = this._shop_shop;
			}
			return shop_shop;
		}
	}
	protected Shop shop
	{
		get
		{
			Shop shop;
			if (this._shop == null)
			{
				this._shop = new Shop();
				shop = this._shop;
			}
			else
			{
				shop = this._shop;
			}
			return shop;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			this.BindPayType();
			this.bindDeliverType();
			this.Bind();
			this.bindAddress();
		}
	}
	private void BindPayType()
	{
		int shopID = 0;
		if (this.shopID != string.Empty)
		{
			shopID = int.Parse(this.shopID);
		}
		DataTable shopByShopID = this.shop_shop.GetShopByShopID(shopID);
		int userID = 0;
		try
		{
			userID = int.Parse(shopByShopID.Rows[0]["ShopOwnerID"].ToString());
		}
		catch
		{
		}
		DataTable payTypeByUserID = this.shop_PayType.GetPayTypeByUserID(userID);
		this.paytype.Items.Clear();
		foreach (DataRow dataRow in payTypeByUserID.Rows)
		{
			ListItem listItem = new ListItem();
			listItem.Text = dataRow["TypeName"].ToString();
			listItem.Value = dataRow["TypeID"].ToString();
			this.paytype.Items.Add(listItem);
		}
	}
	private void bindDeliverType()
	{
		string[] array = this.ProductIDS.Split(new char[]
		{
			','
		});
		int num = 0;
		if (array.Length > 0)
		{
			num = int.Parse(array[0]);
		}
		DataTable dataTable = null;
		if (num > 0)
		{
			dataTable = this.shop_product.GetProductByProductID(num);
		}
		if (dataTable.Rows.Count > 0)
		{
			string text = dataTable.Rows[0]["DeliverPayType"].ToString();
			this.hfdeliverPayType.Value = text;
			if (int.Parse(text) == 0)
			{
				this.deliverInfo.InnerHtml = "卖家承担运费";
				this.confirDeliver.Visible = false;
			}
			else
			{
				this.confirDeliver.Visible = true;
				int delive_TypeID = this.DeliverType.ToInt32(new int[0]);
				ArrayList deliverFashionName = this.shop_deliver.GetDeliverFashionName(delive_TypeID);
				this.rblDeliverFashion.Items.Clear();
				if (deliverFashionName != null)
				{
					for (int i = 0; i < deliverFashionName.Count; i++)
					{
						string text2 = deliverFashionName[i].ToString();
						string[] array2 = text2.Split(new char[]
						{
							'|'
						});
						if (array2.Length > 1)
						{
							ListItem listItem = new ListItem();
							listItem.Text = array2[1].ToString();
							listItem.Value = text2;
							this.rblDeliverFashion.Items.Add(listItem);
						}
					}
				}
				if (this.rblDeliverFashion.Items.Count > 0)
				{
					this.rblDeliverFashion.Items[0].Selected = true;
					this.shop_deliver.GetDeliverTypeInfoByFashionName(this.rblDeliverFashion.SelectedValue, this.deliverType);
				}
			}
		}
	}
	protected void rblDeliverFashion_SelectedIndexChanged(object sender, EventArgs e)
	{
		string selectedValue = this.rblDeliverFashion.SelectedValue;
		if (!string.IsNullOrEmpty(selectedValue))
		{
			this.shop_deliver.GetDeliverTypeInfoByFashionName(selectedValue, this.deliverType);
			this.shop_deliver.SelectDeliverItemByProvince(this.hfdeliverPayType.Value, this.Province.GetSelectValue(new string[0]), this.deliverType);
		}
	}
	private void bindAddress()
	{
		int userId = this.shop.user.UserID;
		this.address_list.Items.Clear();
		if (Fetch.GetCookies("Howave_UserID") != null)
		{
			userId = int.Parse(Fetch.GetCookies("Howave_UserID"));
		}
		DataTable address = this.shop_address.GetAddress(userId);
		foreach (DataRow dataRow in address.Rows)
		{
			string str = dataRow["Province"].ToString();
			string str2 = dataRow["City"].ToString();
			string str3 = dataRow["CMArea"].ToString();
			string str4 = dataRow["Address"].ToString();
			string str5 = str + str2 + str3 + str4;
			ListItem listItem = new ListItem();
			listItem.Text = dataRow["UserName"].ToString() + " " + str5;
			listItem.Value = dataRow["AddressID"].ToString();
			this.address_list.Items.Add(listItem);
		}
		if (this.address_list.Items.Count > 0)
		{
			this.address_list.Items[0].Selected = true;
			this.BindAdressText();
		}
		if (address.Rows.Count == 0)
		{
			this.show_new_address.Visible = true;
			this.ViewState["AddEdit"] = true;
		}
	}
	protected void BindAdressText()
	{
		DataTable addressByID = this.shop_address.GetAddressByID(int.Parse(this.address_list.SelectedValue));
		this.Label1.Text = addressByID.Rows[0]["Province"].ToString();
		this.ContacterName.Text = addressByID.Rows[0]["UserName"].ToString();
		this.TelBox.Text = addressByID.Rows[0]["MobilePhone"].ToString();
		this.HomePhoneBox.Text = addressByID.Rows[0]["ConectPhone"].ToString();
		string text = addressByID.Rows[0]["Province"].ToString();
		this.Province.SelectedValue = text.Trim();
		this.GetCity();
		this.BindArea();
		this.City.SelectedValue = addressByID.Rows[0]["City"].ToString();
		this.GetArea();
		this.ddlArea.SelectedValue = addressByID.Rows[0]["CMArea"].ToString();
		this.Address.Text = addressByID.Rows[0]["Address"].ToString();
		this.EmailBox.Text = addressByID.Rows[0]["Email"].ToString();
		this.zipCode.Text = addressByID.Rows[0]["ZipCode"].ToString();
		this.show_new_address.Visible = true;
		this.CmdNewAddress.Text = "修改";
		this.ViewState["AddEdit"] = false;
		this.shop_deliver.SelectDeliverItemByProvince(this.hfdeliverPayType.Value, this.Province.GetSelectValue(new string[0]), this.deliverType);
	}
	public void Bind()
	{
		this.BindProvince();
		this.BindCity();
		this.BindArea();
	}
	protected void BindProvince()
	{
		DataTable allProvince = this.m_city.GetAllProvince();
		this.Province.Items.Clear();
		this.Province.Items.Add(new ListItem("请选择", ""));
		foreach (DataRow dataRow in allProvince.Rows)
		{
			ListItem listItem = new ListItem();
			listItem.Text = dataRow["Province"].ToString();
			listItem.Value = dataRow["Province"].ToString();
			this.Province.Items.Add(listItem);
		}
		foreach (ListItem listItem2 in this.Province.Items)
		{
			if (listItem2.Value == this.m_selectedProv)
			{
				listItem2.Selected = true;
			}
		}
	}
	protected void BindCity()
	{
		if (!string.IsNullOrEmpty(this.Province.SelectedValue))
		{
			this.GetCity();
			foreach (ListItem listItem in this.City.Items)
			{
				if (listItem.Value == this.m_selectedCity)
				{
					listItem.Selected = true;
				}
			}
		}
		else
		{
			this.City.Items.Clear();
			this.City.Items.Add(new ListItem("请选择", ""));
		}
	}
	protected void GetCity()
	{
		this.City.Items.Clear();
		this.City.Items.Add(new ListItem("请选择", ""));
		if (this.Province.SelectedIndex != 0)
		{
			DataTable city = this.m_city.GetCity(this.Province.SelectedValue);
			if (city != null && city.Rows.Count > 0)
			{
				this.City.DataSource = city;
				this.City.DataTextField = "city";
				this.City.DataValueField = "city";
				this.City.DataBind();
			}
		}
	}
	protected void GetArea()
	{
		this.ddlArea.Items.Clear();
		this.ddlArea.Items.Add(new ListItem("请选择", ""));
		if (!string.IsNullOrEmpty(this.City.GetSelectValue(new string[0])))
		{
			DataTable allAreaByCity = this.m_city.GetAllAreaByCity(this.City.GetSelectValue(new string[0]));
			if (allAreaByCity != null && allAreaByCity.Rows.Count > 0)
			{
				this.ddlArea.DataSource = allAreaByCity;
				this.ddlArea.DataTextField = "area";
				this.ddlArea.DataValueField = "area";
				this.ddlArea.DataBind();
			}
		}
	}
	protected void BindArea()
	{
		if (!string.IsNullOrEmpty(this.City.GetSelectValue(new string[0])))
		{
			this.GetArea();
			foreach (ListItem listItem in this.ddlArea.Items)
			{
				if (listItem.Value.Equals(this.ddlArea.GetSelectValue(new string[0])))
				{
					listItem.Selected = true;
					break;
				}
			}
		}
		else
		{
			this.ddlArea.Items.Clear();
			this.ddlArea.Items.Add(new ListItem("请选择", ""));
		}
	}
	protected void Province_SelectedIndexChanged(object sender, EventArgs e)
	{
		if (this.Province.SelectedValue != "")
		{
			this.Label1.Text = this.Province.SelectedValue;
		}
		else
		{
			this.Label1.Text = "全国";
		}
		string selectValue = this.Province.GetSelectValue(new string[0]);
		this.shop_deliver.SelectDeliverItemByProvince(this.hfdeliverPayType.Value, selectValue, this.deliverType);
		this.GetCity();
		this.GetArea();
	}
	protected void City_SelectedIndexChanged(object sender, EventArgs e)
	{
		this.GetArea();
	}
	protected void CmdNewAddress_Click(object sender, EventArgs e)
	{
		string text = this.Address.Text;
		string selectedValue = this.Province.SelectedValue;
		string selectedValue2 = this.City.SelectedValue;
		string cMArea = "";
		if (!string.IsNullOrEmpty(this.ddlArea.GetSelectValue(new string[0])))
		{
			cMArea = this.ddlArea.GetSelectValue(new string[0]);
		}
		if ((bool)this.ViewState["AddEdit"])
		{
			int num = 10;
			if (!this.m_addr.IsMaxCount(int.Parse(Fetch.GetCookies("Howave_UserID")), num))
			{
				this.m_addr.InsertAddress(int.Parse(Fetch.GetCookies("Howave_UserID")), this.ContacterName.Text, text, this.zipCode.Text, this.HomePhoneBox.Text, this.TelBox.Text, this.EmailBox.Text, selectedValue, selectedValue2, cMArea);
				this.show_new_address.Visible = false;
				this.bindAddress();
			}
			else
			{
				this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('最多只能添加10条记录!');</script>");
			}
		}
		else
		{
			if (!string.IsNullOrEmpty(this.address_list.SelectedValue))
			{
				int addressID = this.address_list.SelectedValue.ToInt32(new int[0]);
				int num2 = this.m_addr.UpdateAddressByAddressID(addressID, this.ContacterName.Text, this.Address.Text, this.zipCode.Text, this.HomePhoneBox.Text, this.TelBox.Text, this.EmailBox.Text, this.Province.GetSelectValue(new string[0]), this.City.GetSelectValue(new string[0]), this.ddlArea.GetSelectValue(new string[0]));
				this.show_new_address.Visible = false;
				this.bindAddress();
				this.address_list.SelectedItem.Value = this.address_list.SelectedValue;
			}
		}
		this.show_new_address.Visible = false;
	}
	protected void LinkAddress_Click(object sender, EventArgs e)
	{
		this.ViewState["AddEdit"] = true;
		this.CmdNewAddress.Text = "添加";
		this.ContacterName.Text = "";
		this.TelBox.Text = "";
		this.HomePhoneBox.Text = "";
		this.zipCode.Text = "";
		this.EmailBox.Text = "";
		this.BindProvince();
		this.BindCity();
		if (this.show_new_address.Visible)
		{
			this.show_new_address.Visible = false;
		}
		else
		{
			this.show_new_address.Visible = true;
		}
		this.shop_deliver.SelectDeliverItemByProvince(this.hfdeliverPayType.Value, this.Province.GetSelectValue(new string[0]), this.deliverType);
	}
	protected void address_list_SelectedIndexChanged(object sender, EventArgs e)
	{
		this.BindAdressText();
	}
}
